﻿using ML.Entity;
using ML.IBusiness;
using ML.IRepository;
using ML.Utils;
using System.Linq;
using System;

namespace ML.Business
{
    public class AdvertisementBusiness : IAdvertisementBusiness
    {
        private readonly IAdvertisementRepository _advertisementRepository;
        public AdvertisementBusiness(IAdvertisementRepository advertisementRepository)
        {
            _advertisementRepository = advertisementRepository;
        }

        public BaseResult<bool> Add(AdvertisementEntity advertisementEntity)
        {
            var res = _advertisementRepository.Add(advertisementEntity);
            if (res)
            {

                return new BaseResult<bool>(200, res);
            }
            else
            {
                return new BaseResult<bool>(201, res);
            }
        }

        public BaseResult<bool> Delete(string id)
        {
            var res = _advertisementRepository.Delete(id);
            if (res)
            {

                return new BaseResult<bool>(200, res);
            }
            else
            {
                return new BaseResult<bool>(201, res);
            };
        }

        public BaseResult<AdvertisementEntity> GetById(string id)
        {
            var data = _advertisementRepository.GetById(id);
            return new BaseResult<AdvertisementEntity>(200, data);
        }

        public BaseResult<Pager<AdvertisementEntity>> List(AdvertisementSearch advertisementSearch)
        {
            //根据传递的条件查询
            Pager<AdvertisementEntity> data = _advertisementRepository.List(advertisementSearch);
            return new BaseResult<Pager<AdvertisementEntity>>(200, data);
        }

        public BaseResult<bool> Update(AdvertisementEntity advertisementEntity)
        {
            var res = _advertisementRepository.Update(advertisementEntity);
            if (res)
            {

                return new BaseResult<bool>(200, res);
            }
            else
            {
                return new BaseResult<bool>(201, res);
            }
        }
    }
}
